package com.kfm.listener;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

@WebListener
public class SessionAttrListener implements HttpSessionAttributeListener {

    @Override
    public void attributeAdded(HttpSessionBindingEvent se) {
        String name = se.getName();
        Object value = se.getValue();
        System.out.println("SessionAttrListener.attributeAdded: " + name + " = " + value);
    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent se) {
        String name = se.getName();
        Object value = se.getValue();
        System.out.println("SessionAttrListener.attributeRemoved: " + name + " = " + value);
    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent se) {
        String name = se.getName();
        Object value = se.getValue();
        System.out.println("SessionAttrListener.attributeReplaced-old: " + name + " = " + value);

        HttpSession session = se.getSession();
        Object newValue = session.getAttribute(name);
        System.out.println("SessionAttrListener.attributeReplaced-new: " + name + " = " + newValue);
    }
}
